<?php

class User {

	protected $id;
	protected $name;
	protected $site;
	protected $language;

	public function __construct(){
		if(is_numeric($this->language)){
			$this->language = Language::GetByID($this->language);
		}
	}

	public function id(){
		return $this->id;
	}

	public function name(){
		return $this->name;
	}

	public static function GetByID($id){
		if($id == 0){
			return new User_Guest();
		}
		$result = Database::getInstance()->query("SELECT * from `users` WHERE `id` = %u AND `site` = %u", $id, Site::getInstance()->GetID());
		if(!($user = $result->fetch_object('User'))){
			throw new User_Not_Found_Exception();
		}
		return $user;
	}

	public function home(){
		$site = Site::getInstance()->getValue('user_home');
		if($site != ''){
			return trim($site, '/');
		}
		return trim($this->home,'/');
	}

	public function language(){
		return $this->language;
	}

}

class User_Guest extends User {

	// Represents Guest Users on the system.

	public function __construct(){
		$this->id = 0;
		$this->language = Language::GetDefault();
		$this->name = $this->language->translate(array('user','guest'));
		$this->site = Site::getInstance()->getID();
	}


}
